package com.polytech.dao.hibernate;

import java.util.Collection;
import java.util.List;

import org.hibernate.Query;

import com.polytech.beans.Brand;
import com.polytech.beans.Car;
import com.polytech.beans.Model;
import com.polytech.dao.CarDao;

public class CarDaoHibernate extends AbstractHibernateDao implements CarDao {

	@Override
	public void insert(Car car) {
		beginTransaction();
		session.save(car);
		commit();
	}

	@Override
	public Car select(String key) {
		beginTransaction();
		Car car=(Car)session.get(Car.class,key);
		commit();
		return car;
	}
	@Override
	public void remove(Car car) {
		beginTransaction();
		session.delete(car);
		commit();
		
	}

	@Override
	public Collection<Car> selectAll() {
		List<Car> res=null;
		beginTransaction();
			res= (List<Car>) session.createQuery("from Car").list();
		commit();
		return res;
	}

	
}
